
<%@ page import="auctionhaus.Listing" %>
<!doctype html>
<html>
	<head>
		<meta name="layout" content="main">
		<g:set var="entityName" value="${message(code: 'listing.label', default: 'Listing')}" />
		<title><g:message code="default.list.label" args="[entityName]" /></title>
	</head>
	<body>
		<a href="#list-listing" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content&hellip;"/></a>
		<div class="nav" role="navigation">
			<ul>
				<li><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>
                <g:if test="${session.customer}">
				    <li><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></li>
                </g:if>
                <g:if test="${myList}">
                    <li><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></li>
                </g:if>
                <g:if test="${!myList && session.customer}">
                    <li><g:link class="list" action="myList"><g:message code="default.myList.label" args="[entityName]" default="My Listings"/></g:link></li>
                </g:if>
                <g:if test="${session.customer && session.customer.isAdmin}">
                    <li><g:link class="list" controller="customer" action="list"><g:message code="default.myList.label" args="[entityName]" default="Customer List"/></g:link></li>
                </g:if>
			</ul>
		</div>
		<div id="list-listing" class="content scaffold-list" role="main">
			<h1><g:message code="default.list.label" args="[entityName]" /></h1>
            <div id="message2">
                <g:if test="${flash.message}">
                <div class="message" role="status">${flash.message}</div>
                </g:if>
            </div>
			<table>
				<thead>
					<tr>
					
						<g:sortableColumn property="name" title="${message(code: 'listing.name.label', default: 'Name')}" />
					
						<th><g:message code="listing.num_bids.label" default="# bids" /></th>
					
						<g:sortableColumn property="startingBidAmount" title="${message(code: 'listing.startingBidAmount.label', default: 'Starting Price')}" />

                        <g:sortableColumn property="dateCreated" title="${message(code: 'listing.dateCreated.label', default: 'Start Date/Time')}" />

                        <g:sortableColumn property="endDateTime" title="${message(code: 'listing.endDateTime.label', default: 'End Date/Time')}" />
					
					</tr>
				</thead>
				<tbody>
				<g:each in="${listingInstanceList}" status="i" var="listingInstance">
					<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">

                        <td><g:remoteLink action="isExpired" id="${listingInstance.id}" onSuccess="isExpired(data, status)">${fieldValue(bean: listingInstance, field: "name")}</g:remoteLink></td>
					
						<td>${listingInstance.bids.size()}</td>
					
						<td><g:formatNumber number="${listingInstance.startingBidAmount}" type="currency" currencyCode="USD" /></td>

                        <td><g:formatDate date="${listingInstance.dateCreated}"  type="datetime" style="MEDIUM"/></td>

						<td><g:formatDate date="${listingInstance.endDateTime}"  type="datetime" style="MEDIUM"/></td>
					
					</tr>
				</g:each>
                <g:javascript>
                    function isExpired(data, status) {
                        if (data.expired)
                        {
                            $("#message2").addClass("message").attr("role", "status").text("Listing expired.");
                        }
                        else
                        {
                            window.location = "/AuctionHaus/listing/show/" + data.id
                        }
                    }
                </g:javascript>
				</tbody>
			</table>
			<div class="pagination">
				<g:paginate total="${listingInstanceTotal}" />
			</div>
		</div>
	</body>
</html>
